public class demo1 {
    public static void main(String[] args) {
        String str = "a";
        Thread t1 = new Thread(() ->{
//          synchronized (demo2.class){
            synchronized (str){
                System.out.println("t1开始");
                try {
                    Thread.sleep(1000);
                    System.out.println("t1结束");
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        t1.start();
        Thread t2 = new Thread(() -> {
//            synchronized (demo2.class){
            synchronized (str){
                System.out.println("t2开始");
                try {
                    Thread.sleep(1000);
                    System.out.println("t2结束");
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        t2.start();
    }
}
